<?php

namespace App\Http\Services;

use App\Http\Model\ActivityMall;
use App\Http\Model\ActivityPearl;
use App\Http\Model\AudioApi;
use App\Http\Model\Config;
use App\Http\Model\MoonDial;
use App\Http\Model\MoonGift;
use App\Http\Model\MoonInviteUser;
use App\Http\Model\MoonRabbit;
use App\Http\Model\MoonRecharge;
use App\Http\Model\RankCache;
use App\Http\Model\Room;
use App\Http\Model\User;
use Illuminate\Support\Facades\Redis;

class MoonServices extends CommonServices
{
    public function __construct()
    {
        $this->moonRecharge = new MoonRecharge();
        $this->configModel = new Config();
        $this->audioApi = new AudioApi();
        $this->moonRabbit = new MoonRabbit();
        $this->moonInviteUser = new MoonInviteUser();
        $this->moonGift = new MoonGift();
        $this->moonDial = new MoonDial();
        $this->kkaudioUser = new User();
        $this->activityPearl = new ActivityPearl();
        $this->activityMall = new ActivityMall();
        $this->rankCache = new RankCache();
        $this->room = new Room();
    }


    public function getUserLog($user_id, $now_date, $body = [])
    {
        $log = $this->moonRecharge->getLog($user_id, $now_date);
        if (!$log) {
            //获取用户充值记录
            $allLog = $this->moonRecharge->getAllLog($user_id);
            $rank = !$allLog ? 1 : count($allLog) + 1;
            return $this->moonRecharge->create($body, $rank, $now_date);
        }
        return true;
    }

    public function checkUserRabbit($user_id)
    {
        $res = $this->moonInviteUser->getInviteUser($user_id);
        if (!$res) {
            return false;
        }
        $invite_uid = $res->invite_uid;
        $update = $this->moonInviteUser->updateStatus($user_id);
        if (!$update) {
            write_log('moonConsumer', 'updateRechargeUserError', [$user_id]);//更新充值失败
        }
        //添加邀请玉兔
        $cp_rabbit = $this->moonRabbit->getRabbit($invite_uid);
        if (!$cp_rabbit) {
            return false;
        }
        $ret = $this->moonRabbit->updateRabbit($invite_uid);
        if (!$ret) {
            write_log('moonConsumer', 'checkInviteUserLoginError', [$user_id, $invite_uid]);
            return false;
        }
        write_log('moonConsumer', 'checkInviteUserLoginSuccess', [$user_id, $invite_uid]);
        return true;

    }


    //获取用户礼包
    public function getUserGift($user_id)
    {
        $res = $this->moonRecharge->getAllLog($user_id, ['user_id', 'rank', 'gift_log', 'status', 'created_date']);
        $count = count($res);
        foreach ($res as $k => &$v) {
            $v->is_now = 0;
            if ($k == $count - 1) {
                $log_date = $v->created_date;
                if ($log_date == date('Y-m-d', time())) {
                    $v->is_now = 1;
                }
            }
            if (!empty($v->gift_log)) {
                $log = json_decode($v->gift_log, true);
                $gift_log['pearl_num'] = $log['pearl_num'];
                if (empty($log['goods_id'])) {
                    $gift_log['status'] = 0;
                } else {
                    $gift_log['status'] = 1;
                }
                $v->gift_log = $gift_log;
            } else {
                $v->gift_log = [];
            }
        }
        if ($count < 7) {
            $nullArr = [];
            for ($i = $count + 1; $i <= 7; $i++) {
                $nullArr[$i]['user_id'] = $user_id;
                $nullArr[$i]['rank'] = $i;
                $nullArr[$i]['gift_log'] = [];
                $nullArr[$i]['status'] = -1;
                $nullArr[$i]['created_date'] = '';
                $nullArr[$i]['is_now'] = 0;
            }
            if ($res) {
                if ($res[$count - 1]->is_now == 0) {
                    $nullArr[$count + 1]['is_now'] = 1;
                }
            } else {
                $nullArr[$count + 1]['is_now'] = 1;
            }
            $res = array_merge($res, $nullArr);
        }
        return $res;
    }

    //用户点击礼包
    public function clickGift($user_id, $rank)
    {
        $config = $this->configModel->getShareGoodsConfig(5);
        $activity_date = explode(' - ', $config['moon_date']['value']);
        if (date('Y-m-d H:i:s', time()) > $activity_date[1]) {
            return ['code' => 406, 'msg' => '活动过期', 'gift_log' => []];
        }
        $res = $this->moonRecharge->checkUserBag($user_id, $rank);
        $pearl_num = rand(180, 600);
        $gift['user_id'] = $user_id;
        $gift['goods_id'] = '';
        $gift['goods_type'] = '';
        $gift['time_limit'] = '';
        switch ($rank) {
            case 1:
                $gift['goods_id'] = $config['moon_bubble_id']['value'];
                $gift['goods_type'] = 1;
                $gift['time_limit'] = 3;
                break;
            case 2:
                $gift['goods_id'] = $config['moon_headwear_id']['value'];
                $gift['goods_type'] = 1;
                $gift['time_limit'] = 3;
                break;
            case 3:
                $pro2 = rand(0, 999);
                if ($pro2 < 3) {
                    $gift['goods_id'] = 35;
                    $gift['goods_type'] = 2;
                    $gift['time_limit'] = 7;
                }
                break;
            case 4:
                $gift['goods_id'] = $config['moon_bubble_id']['value'];
                $gift['goods_type'] = 1;
                $gift['time_limit'] = 5;
                break;
            case 5:
                $pearl_num = rand(240, 720);
                $gift['goods_id'] = $config['moon_headwear_id']['value'];
                $gift['goods_type'] = 1;
                $gift['time_limit'] = 5;
                break;
            case 6:
                $pearl_num = rand(300, 780); //修改  喵喵座驾
                $pro6 = rand(0, 999);
                if ($pro6 == 0) {
                    $gift['goods_id'] = 35;
                    $gift['goods_type'] = 2;
                    $gift['time_limit'] = 7;
                }
                break;
            case 7:
                $pearl_num = rand(420, 900);
                $gift['goods_id'] = $config['moon_ring_id']['value'];
                $gift['goods_type'] = 4;
                $gift['time_limit'] = 0;
                break;
            default:
        }

        $code = 200;
        $msg = '成功';
        $gift_log = '';
        do {
            if (!$res) {
                $code = 401;
                $msg = '不可领取';
                break;
            }
            if ($res->status == 1) {
                $code = 202;
                $msg = '已经领取';
                $gift_log = json_decode($res->gift_log, true);
                break;
            }
            if ($res->status == 0) {
                //领取礼包 发送
                if (!empty($gift['goods_id'])) { //赠送商品
                    if ($rank == 7) {//赠送钻戒
                        $api = $this->audioApi->sendRing($user_id, $gift['goods_id'], 0);
                        $this->activityMall->create($user_id, $gift['goods_id'], 5, 0, 1, 1);
                    } else {
                        $api = $this->audioApi->sendUsedMall($gift);
                        $this->activityMall->create($user_id, $gift['goods_id'], $gift['goods_type'], $gift['time_limit'], 1, 1);
                    }
                    if (!$api) {
                        write_log('moonConsumer', 'sendMallApiError', $gift);//奖励金豆api添加失败
                        $code = 402;
                        $msg = '商品赠送失败';
                        break;
                    }
                }
                $pearl_api = $this->audioApi->pearl_recharge($user_id, $pearl_num, '中秋活动领取金豆');
                if (!$pearl_api) {
                    write_log('moonConsumer', 'rechargePearlApiError', [$user_id, $pearl_num, $msg]);//奖励金豆api添加失败
                    $code = 402;
                    $msg = '金豆赠送失败';
                    break;
                }
                $this->activityPearl->create($user_id, $pearl_num, 1, 1);
                $data['status'] = 1;
                $data['gift_log'] = json_encode(array_merge($gift, ['pearl_num' => $pearl_num]));
                $res = $this->moonRecharge->updateLog($user_id, $rank, $data);
                if (!$res) {
                    $code = 402;
                    $msg = '领取失败';
                    break;
                }
                //发送消息通知
                $this->audioApi->sendMsgApi($user_id, '中秋礼包奖励已到账');
                break;
            }
        } while (false);
        return ['code' => $code, 'msg' => $msg, 'gift_log' => $gift_log];
    }


    public function send_register($phone, $sms_code, $password, $invite_uid)
    {
        $data['phone'] = $phone;
        $data['sms_code'] = $sms_code;
        $data['password'] = $password;
        $data['invite_uid'] = $invite_uid;
        $res = $this->audioApi->registerApi($data);
        $ret['code'] = 200;
        $ret['msg'] = '成功';
        $ret['data'] = [];
        do {
            if ($res['code'] != 0) {
                $ret['code'] = $res['code'];
                $ret['msg'] = $res['msg'];
                break;
            }
            $ret['data'] = $res['data'];
            break;
        } while (false);
        return $ret;
    }

    public function createInviteUser($new_user, $user_id)
    {
        $cp_log = $this->moonRabbit->getRabbit($user_id);
        if (!$cp_log) {
            $this->moonRabbit->create($user_id);
        }
        $this->moonRabbit->updateInviteNum($user_id);
        return $this->moonInviteUser->create($new_user, $user_id);
    }

    //兑换亲密值
    public function convert($user_id, $type = 1, $num = 1)
    {
        $config = $this->configModel->getShareGoodsConfig(5);
        $activity_date = explode(' - ', $config['moon_date']['value']);
        if (date('Y-m-d H:i:s', time()) > $activity_date[1]) {
            return ['code' => 406, 'msg' => '活动过期'];
        }
        //查看用户玉兔
        $user_fowl_num = $this->moonRabbit->getRabbit($user_id);
        if (!$user_fowl_num) {
            return ['code' => 404, 'msg' => '您还未邀请用户注册或邀请用户未充值，请重试'];
        }
        $config = $this->configModel->getShareGoodsConfig(5);
        $code = 200;
        $msg = '成功';
        if ($user_fowl_num->real_num < $num) {
            return ['code' => 401, 'msg' => '您的玉兔数量不足，请重试'];
        }

        $intimacy_vaule = 0;
        $api = false;
        switch ($type) {
            case 1:
                //验证cp关系
                $user_cp = $this->moonRabbit->getUserCp($user_id);
                if (!$user_cp) {
                    $code = 203;
                    $msg = '您还没有cp，不可以兑换亲密值';
                    break;
                }
                if ($user_fowl_num->consumer_intimacy_num + $num > 100) {
                    $code = 410;
                    $msg = '您的兑换亲密值已超过100点';
                    break;
                }
                $api = $this->audioApi->sendIntimacyValue($user_id, $user_cp['cp_user_id'], $num);
                $this->activityPearl->create($user_id, $num, 1, 3, 3);
                $intimacy_vaule = $num;
                break;
            case 2:
                $mallData['user_id'] = $user_id;
                $mallData['goods_id'] = $config['moon_card_id']['value'];
                $mallData['goods_type'] = 4;
                $mallData['time_limit'] = 7;
                $api = $this->audioApi->sendUsedMall($mallData);
                $intimacy_vaule = 20;
                $this->activityMall->create($user_id, $mallData['goods_id'], $mallData['goods_type'], $mallData['time_limit'], 1, 2);
                break;
        }
        if (!$api) {
            write_log('moonConsumer', 'convertMallError', [$user_id, $user_id, 'num' => $num, 'type' => $type]);
        }

        //减少用户可用玉兔数量
        $this->moonRabbit->updateRabbitToConvert($user_id, $intimacy_vaule, $type);
        return ['code' => $code, 'msg' => $msg];
    }


    public function getUserRabbitNum($user_id)
    {
        $rabbit = $this->moonRabbit->getRabbit($user_id);
        $data['rabbit_num'] = 0;
        $data['real_num'] = 0;
        $data['convert_intimacy'] = 100;
        $data['user_id'] = $user_id;
        $data['portrait'] = '';
        if ($rabbit) {
            $user_info = $this->kkaudioUser->getUserInfoByKkaudio($user_id);
            $img = json_decode($user_info['portrait'], true);
            $portrait = $img[0] ?? '';
            if (strpos($portrait, 'http:') === false) {
                $portrait = env('APP_PIC_DOMAIN') . $portrait;
            }
            $data['user_id'] = $user_id;
            $data['portrait'] = $portrait;
            $data['rabbit_num'] = $rabbit->rabbit_num;
            $data['real_num'] = $rabbit->real_num;
            $data['convert_intimacy'] = 100 - $rabbit->consumer_intimacy_num;
        }
        return $data;
    }


    public function checkTicket($user_id, $num = 0)
    {
        $log = $this->moonGift->getNum($user_id);
        $code = 200;
        $msg = '成功';
        $data = [];
        $config = $this->configModel->getShareGoodsConfig(5);
        $config_date = explode(' - ', $config['moon_date']['value']);
        $activity_date = $config_date[1];
        $config_liang = array_flip(explode(',', $config['moon_liang_num']['value']));
        do {
            if (date('Y-m-d H:i:s', time()) < $activity_date) {
                $code = 401;
                $msg = '请在9月18日，00:00-24:00开始抽奖';
                break;
            }
            $activity_end_date = date('Y-m-d H:i:s', strtotime($activity_date) + 86400);
            if (date('Y-m-d H:i:s', time()) > $activity_end_date) {
                $code = 401;
                $msg = '请在9月18日，00:00-24:00内翻牌';
                break;
            }
            if (!$log) {
                $code = 201;
                $msg = '您还未获得抽奖券';
                break;
            }
            if ($log->ticket_num < $num) {
                $code = 202;
                $msg = '抽奖券不足，请重试';
                break;
            }
//            用户消耗抽奖券
            $consumer_ticket = $this->moonGift->decrementNum($user_id, $num);
            if (!$consumer_ticket) {
                write_log('dialTicket', 'ticketError', ['user_id' => $user_id, 'num' => $num]);//抽奖券使用错误
                $code = 203;
                $msg = '抽奖券使用失败，请重试';
                break;
            }
            //查看所有用户抽奖券
            $user_ticket = $this->moonGift->getAllTicket();
            $consumer_sum = $user_ticket['consumer_sum'];
            $ticket_sum = $rand_max = $user_ticket['ticket_sum'] + $user_ticket['consumer_sum'];
            $odds = round($consumer_sum / $ticket_sum, 2);
            $liang_cache = Redis::lrange('moon_liang', 0, -1);
            $count_cache = count($liang_cache);
            if ($odds <= 0.5 && $count_cache > 4) {
                $rand_max = $ticket_sum - $consumer_sum;
            }
            $get_dial_award = $this->getDialAward($rand_max, $num);
            $data = $get_dial_award['data'];
            //查看用户是否抽到靓号
            $dial_log = $this->moonDial->getNumToLiang($user_id);
            if ($get_dial_award['flag'] !== 0) {
                $gift_type = 4;
                $liang_num = Redis::lindex('moon_liang', 0);
                if ($dial_log === false && !is_null($liang_num)) {
                    //赠送靓号
                    $sort = $config_liang[$liang_num];
                    switch ($sort) {
                        case 0:
                            $liang_sort = 0;
                            break;
                        case 1:
                            $liang_sort = 2;
                            break;
                        case 2:
                            $liang_sort = 4;
                            break;
                        case 3:
                            $liang_sort = 5;
                            break;
                        case 4:
                            $liang_sort = 7;
                            break;
                        case 5:
                            $liang_sort = 8;
                            break;
                        default:
                            $liang_sort = 6;
                    }
                    Redis::lpop('moon_liang');
                    write_log('dialTicket', 'liangSuccess', ['user_id' => $user_id, 'liang_num' => $liang_num]);//抽奖券使用成功
                    //发送消息
                    $this->audioApi->sendAllAppApi($user_id);
                    //发送消息
                    $this->audioApi->sendMsgApi($user_id, '恭喜您在中秋转盘抽奖活动中获得靓号:' . $liang_num . '，手气爆翻天啦！');
                } else {
                    $gift_type = 2;
                    $liang_num = 815;
                    $liang_sort = 6;
                }
                $liang_data[] = ['gift_type' => $gift_type, 'gift_value' => $liang_num, 'gift_sort' => $liang_sort];
                $data = array_merge($get_dial_award['data'], $liang_data);
            }
            //获取所有中将类型
            $type_data = array_flip(array_values(array_unique(array_column($data, 'gift_type'))));
            foreach ($type_data as $k => $v) {
                $insert_data[$k]['user_id'] = $user_id;
                $insert_data[$k]['num_count'] = 0;
                $insert_data[$k]['gift_type'] = $k;
                $insert_data[$k]['gift_value'] = 0;
            }
            //统计中奖类型 对应数量
            foreach ($data as $v) {
                $insert_data[$v['gift_type']]['num_count']++;
                $insert_data[$v['gift_type']]['gift_value'] += $v['gift_value'];
            }
            //发放中奖礼物
            foreach ($insert_data as $v) {
                switch ($v['gift_type']) {
                    case 0: //勋章
                        $this->audioApi->sendMedal($user_id, $config['moon_medal_id']['value'], $v['gift_value']);
                        break;
                    case 1://头饰
                        $this->audioApi->sendUsedMall(['user_id' => $user_id, 'goods_id' => $config['moon_headwear_id']['value'], 'goods_type' => 1, 'time_limit' => $v['gift_value']]);
                        break;
                    case 2: //气泡
                        $this->audioApi->sendUsedMall(['user_id' => $user_id, 'goods_id' => $config['moon_bubble_id']['value'], 'goods_type' => 3, 'time_limit' => $v['gift_value']]);
                        break;
                    case 3://金豆
                        $this->audioApi->pearl_recharge($user_id, $v['gift_value'], '中秋活动抽奖赠送');
                        break;
                    default:
                }
            }
            //新增中奖纪录
            $insertBatch = $this->moonDial->insertBatch($insert_data);
            if (!$insertBatch) {
                write_log('dialTicket', 'insertBatchError', $insert_data);//记录生成失败
            } else {
                write_log('dialTicket', 'ticketSuccess', ['user_id' => $user_id, 'num' => $num]);//抽奖券使用成功
            }
        } while (false);
        return ['code' => $code, 'msg' => $msg, 'data' => $data];
    }


    /*
     * $rand_type = 0 勋章  1：头饰  2：气泡 3 金豆
     *
     * */
    protected function getDialAward($rand_max = 100000, $num = 1)
    {
        $flag = 0;//0未抽取靓号
        $data = [];
        $day = [1, 2, 3];
        $pearl_value = [15, 80, 666, 815];
        for ($i = 0; $i < $num; $i++) {
            $rand_type = rand(0, 3);
            $rand_day_value = rand(0, 2);
            $rand_pearl_value = rand(0, 3);
            $res = rand(0, $rand_max);
            if ($res < 6 && $flag == 0) {
                $flag = 1;
                continue;
            }
            $data[$i]['gift_type'] = $rand_type;
            $data[$i]['gift_value'] = $day[$rand_day_value];
            switch ($rand_type) {
                case 0:
                    $data[$i]['gift_sort'] = 9;
                    break;
                case 1:
                    $data[$i]['gift_sort'] = 1;
                    break;
                case 2:
                    $data[$i]['gift_sort'] = 3;
                    break;
                case 3:
                    $data[$i]['gift_sort'] = 6;
                    $data[$i]['gift_value'] = $pearl_value[$rand_pearl_value];
                    break;
                default:
            }
        }
        return ['flag' => $flag, 'data' => $data];
    }


    public function getDialAwardLog($user_id)
    {
        $res = $this->moonDial->getLog($user_id);
        foreach ($res as $v) {
            $time = explode(' ', $v->created_at);
            $year = explode('-', $time[0]);
            $v->year = $year[0] . '-' . substr($year[1], 1) . '-' . substr($year[2], 1);
            $v->hour = $time[1];
        }
        return $res;
    }

    public function getUserTicketNum($user_id)
    {
        $data['user_id'] = $user_id;
        $data['ticket_num'] = 0;
        $data['consumer_num'] = 0;
        $res = $this->moonGift->getNum($user_id);
        if ($res) {
            $data['ticket_num'] = $res->ticket_num;
            $data['consumer_num'] = $res->consumer_num;
        }
        return $data;
    }

    public function payMoonGift($user_id, $num)
    {
        $log = $this->moonGift->getNum($user_id);
        if (!$log) {
            $res = $this->moonGift->create($user_id, $num);
        } else {
            $res = $this->moonGift->incrementNum($user_id, $num);
        }
        return $res;
    }

    public function roomRank($body)
    {
        $user_id = $body['user_id'] ?? 0;
        $room_id = $body['room_id'] ?? 0;
        $to_user_ids = $body['to_user_id_array'] ?? [];
        $config = $this->configModel->getShareGoodsConfig(5);
        $res = [
            $config['moon_crab_id']['value'] => 4,
            $config['moon_cake_id']['value'] => 1,
        ];
        if (!in_array($body['gift_id'], array_keys($res))) {
            return false;
        }
        $score = $res[$body['gift_id']] * count($to_user_ids) * $body['gift_num'];
        return $this->rankCache->incRank($user_id, $to_user_ids, $room_id, $score);
    }

    public function giftRank($user_id)
    {
        $key = $user_id;
        $send_rank = $this->rankCache->allSendRank();
        $collect_rank = $this->rankCache->allCollectRank();
        $room_rank = $this->rankCache->allRoomRank();
        $room = $this->room->getRoomInfoToUserId($user_id);
        $user_send_rank = $user_collect_rank = $rank_room = '未上榜';
        if (in_array($key, $send_rank)) {
            $send_rank = array_flip($send_rank);
            $user_send_rank = $send_rank[$key] + 1;
        }
        if (in_array($key, $collect_rank)) {
            $collect_rank = array_flip($collect_rank);
            $user_collect_rank = $collect_rank[$key] + 1;
        }
        if ($room) {
            $key = $room['room_id'];
            if (in_array($key, $room_rank)) {
                $room_rank = array_flip($room_rank);
                $rank_room = $room_rank[$key] + 1;
            }
        }
        return ['0' => $user_send_rank, '1' => $user_collect_rank, '2' => $rank_room];
    }


    public function awardGift()
    {
        $allSendRank = $this->rankCache->allSendRank();
        $this->giftAwardToUserId($allSendRank);
        $allCollectRank = $this->rankCache->allCollectRank();
        $this->giftAwardToUserId($allCollectRank);
        return true;
    }

    public function userRankList()
    {
        $data['send'] = $this->rankCache->allSendRank();
        $data['collect'] = $this->rankCache->allCollectRank();
        return $data;
    }
    public function room_rank_list()
    {
        return $this->rankCache->allRoomRank();
    }


    //发放奖励   1：头饰 2：座驾  3：气泡
    public function giftAwardToUserId($user_ids)
    {
        $config = $this->configModel->getShareGoodsConfig(5);
        $moon_bubble_id = explode(',', $config['moon_bubble_rank_id']['value']);
        $moon_headwear_ids = explode(',', $config['moon_headwear_rank_id']['value']);
        $moon_mount_ids = explode(',', $config['moon_mount_rank_id']['value']);
        $moon_medal_rank_id = $config['moon_medal_rank_id']['value'];
        $moon_card_rank_id = $config['moon_card_rank_id']['value'];
        foreach ($user_ids as $k => $val) {
            $user_id = $val;
            switch ($k) {
                case 0;//第一名
                    $this->audioApi->sendMedal($user_id, $moon_medal_rank_id, 0); //勋章
                    $this->audioApi->sendUsedMall(['user_id' => $user_id, 'goods_id' => $moon_headwear_ids[0], 'goods_type' => 1, 'time_limit' => 30]);//头饰
                    $this->audioApi->sendUsedMall(['user_id' => $user_id, 'goods_id' => $moon_mount_ids[0], 'goods_type' => 2, 'time_limit' => 15]); //座驾
                    $this->audioApi->sendUsedMall(['user_id' => $user_id, 'goods_id' => $moon_bubble_id[0], 'goods_type' => 3, 'time_limit' => 30]);//气泡
                    $this->audioApi->sendUsedMall(['user_id' => $user_id, 'goods_id' => $moon_card_rank_id, 'goods_type' => 4, 'time_limit' => 15]);//名片装扮
                    break;
                case 1://第二名
                    $this->audioApi->sendMedal($user_id, $moon_medal_rank_id, 0); //勋章
                    $this->audioApi->sendUsedMall(['user_id' => $user_id, 'goods_id' => $moon_headwear_ids[1], 'goods_type' => 1, 'time_limit' => 15]);//头饰
                    $this->audioApi->sendUsedMall(['user_id' => $user_id, 'goods_id' => $moon_mount_ids[1], 'goods_type' => 2, 'time_limit' => 15]); //座驾
                    $this->audioApi->sendUsedMall(['user_id' => $user_id, 'goods_id' => $moon_bubble_id[1], 'goods_type' => 3, 'time_limit' => 15]);//气泡
                    $this->audioApi->sendUsedMall(['user_id' => $user_id, 'goods_id' => $moon_card_rank_id, 'goods_type' => 4, 'time_limit' => 7]);//名片装扮
                    break;
                case 2://第三名
                    $this->audioApi->sendMedal($user_id, $moon_medal_rank_id, 0); //勋章
                    $this->audioApi->sendUsedMall(['user_id' => $user_id, 'goods_id' => $moon_headwear_ids[1], 'goods_type' => 1, 'time_limit' => 7]);//头饰
                    $this->audioApi->sendUsedMall(['user_id' => $user_id, 'goods_id' => $moon_mount_ids[2], 'goods_type' => 2, 'time_limit' => 15]); //座驾
                    $this->audioApi->sendUsedMall(['user_id' => $user_id, 'goods_id' => $moon_bubble_id[1], 'goods_type' => 3, 'time_limit' => 7]);//气泡
                    $this->audioApi->sendUsedMall(['user_id' => $user_id, 'goods_id' => $moon_card_rank_id, 'goods_type' => 4, 'time_limit' => 7]);//名片装扮
                    break;
                case 3://第四名
                    $this->audioApi->sendMedal($user_id, $moon_medal_rank_id, 7); //勋章
                    $this->audioApi->sendUsedMall(['user_id' => $user_id, 'goods_id' => $moon_headwear_ids[1], 'goods_type' => 1, 'time_limit' => 7]);//头饰
                    $this->audioApi->sendUsedMall(['user_id' => $user_id, 'goods_id' => $moon_bubble_id[1], 'goods_type' => 3, 'time_limit' => 7]);//气泡
                    $this->audioApi->sendUsedMall(['user_id' => $user_id, 'goods_id' => $moon_card_rank_id, 'goods_type' => 4, 'time_limit' => 7]);//名片装扮
                    break;
                case 4://第五名
                    $this->audioApi->sendUsedMall(['user_id' => $user_id, 'goods_id' => $moon_headwear_ids[1], 'goods_type' => 1, 'time_limit' => 7]);//头饰
                    $this->audioApi->sendUsedMall(['user_id' => $user_id, 'goods_id' => $moon_bubble_id[1], 'goods_type' => 3, 'time_limit' => 7]);//气泡
                    $this->audioApi->sendUsedMall(['user_id' => $user_id, 'goods_id' => $moon_card_rank_id, 'goods_type' => 4, 'time_limit' => 7]);//名片装扮
                    break;
                default:

            }
            $this->audioApi->sendMsgApi($user_id, '月圆中秋——"奖励已发放，您可到个性装扮查收礼品哦~');
        }
        return true;
    }


    public function createNewCacheKey()
    {
       return $this->rankCache->createNewCacheKey();
    }


}